package com.lanou.elh.members.web.controller;

import com.lanou.elh.members.entity.Address;
import com.lanou.elh.members.entity.Member;
import com.lanou.elh.members.service.MemberService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/member")
public class memberController {
    @Autowired
    private MemberService memberService;
    @PostMapping("/registerMember")
    @ApiOperation(value = "注册商城会员")
    public Map<String,Object> register(Member member){
        //member 用户信息
        memberService.register(member);
        Map<String,Object> map = new HashMap<>();
        return map;
    }

    @PostMapping("/addAddress")
    @ApiOperation(value = "用户添加地址")
    public Map<String,Object> addAddress(Address address){
        //address 地址信息
        memberService.addAddress(address);
        Map<String,Object> map = new HashMap<>();
        return map;
    }

    @DeleteMapping("/delAddress")
    @ApiOperation(value = "用户删除地址")
    public Map<String,Object> deleteAddress(Integer addressId){
        //addressId 要删除的地址id
        memberService.deleteAddress(addressId);
        Map<String,Object> map = new HashMap<>();
        return map;
    }

    @PutMapping("editAddress")
    @ApiOperation(value = "用户修改地址")
    public Map<String,Object> editAddress(Address address){
        //address 要修改的地址信息
        memberService.editAddress(address);
        Map<String,Object> map = new HashMap<>();
        return map;
    }

    @PutMapping("/editMember")
    @ApiOperation(value = "用户编辑地址信息")
    public Map<String,Object> editMember(Member member){
        // member 要编辑的用户信息
        memberService.editMember(member);
        Map<String,Object> map = new HashMap<>();
        return map;
    }
}
